package org.tech4j.captcha.api.model;

/**
 * @program: tech4j
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/4 11:47
 **/
public class CaptchaResponse {
    /**
     * 结果码
     */
    private String errorCode;

    /**
     * 结果信息
     */
    private String message;

    /**
     * 是否成功
     */
    private Boolean success;

    /**
     * 返回数据
     */
    private Object data;

    public static CaptchaResponse ofFailed(String errorCode, String message) {
        return Builder.builder()
                .errorCode(errorCode)
                .message(message)
                .success(false)
                .build();
    }

    public static CaptchaResponse ofSuccess() {
        return Builder.builder()
                .errorCode("0")
                .success(true)
                .build();
    }

    public static CaptchaResponse ofSuccess(Object data) {
        return Builder.builder()
                .errorCode("0")
                .success(true)
                .data(data)
                .build();
    }


    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static final class Builder {
        private String errorCode;
        private String message;
        private Boolean success;
        private Object data;

        private Builder() {
        }

        public static Builder builder() {
            return new Builder();
        }

        public Builder errorCode(String errorCode) {
            this.errorCode = errorCode;
            return this;
        }

        public Builder message(String message) {
            this.message = message;
            return this;
        }

        public Builder success(Boolean success) {
            this.success = success;
            return this;
        }

        public Builder data(Object data) {
            this.data = data;
            return this;
        }

        public CaptchaResponse build() {
            CaptchaResponse captchaResponse = new CaptchaResponse();
            captchaResponse.setErrorCode(errorCode);
            captchaResponse.setMessage(message);
            captchaResponse.setSuccess(success);
            captchaResponse.setData(data);
            return captchaResponse;
        }
    }

    public boolean isFailed() {
        return Boolean.FALSE.equals(success);
    }
}
